/**
 * Created by SunLunatic on 2015/4/3.
 */
var mongodb = require("mongodb");
var monk = require("monk");
var extend = require('extend');
var uuid = require("uuid");
var db = monk('localhost:27017/rose');

var data = {
    server : "www.voidsun.com"
}

exports.getDb = function(data){
    return db.get(data);
}

exports.getServer = function(){
    return data.server;
}

exports.genid = function(){
    return uuid.v1();
}

exports.baseData = function(req, resbody){
    resbody.data = data;
    return resbody;
}

exports.insert = function (tablename, callback) {
    var ids = db.get('ids');
    ids.findAndModify({"tablename":tablename}, {$inc:{'id':1}}, {new:true, upsert:true}, function(err, doc) {
        callback(doc.id);
    });
}